package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.PermissionMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();

        QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(queryString)) {
            queryWrapper.like("name", queryString);
        }
        Page<Permission> page = page(new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), queryWrapper);
        return new PageResult(page.getTotal(), page.getRecords());
    }

}
